<template>
  <div id="activityAgo">
    <router-link
      tag="li"
      :to="{name:'activity',params:{id:ago.gameTitleId}}"
      v-for="ago in activityAgo"
      :key="ago.gameTitleId"
    >
      <a>
        <span class="gameTitleId">{{ago.gameTitleId}}</span>
        <div class="ago_img">
          <div class="agoimg">
            <img :src="'/api/upload/' + ago.gameTitleImg" alt />
          </div>
        </div>
        <p>{{ago.gameTitleName}}</p>
        <br />
        <span class="number">{{formateDate(ago.gameBeginTime)}} - {{formateDate(ago.gameEndTime)}}</span>
      </a>
    </router-link>
  </div>
</template>
<script>
export default {
  data() {
    return {
      activityAgo: []
    };
  },
  created() {
    this.$axios
      .get("/api/gameTitle/getGameTitle")
      .then(res => {
        // console.log('res:',res.data.data)
        this.activityAgo = res.data.data;
        console.log("this.activityAgo", this.activityAgo);
      })
      .catch(err => {
        console.log("err:", err);
      });
  },
  methods:{
    // 时间格式转换
    formateDate:function(datetime) {
      function addDateZero(num) {
          return (num < 10 ? "0" + num : num)
      }
      let d = new Date(datetime)
      let formatdatetime = d.getFullYear() + '-' + 
      addDateZero(d.getMonth() + 1) + '-' + addDateZero(d.getDate())
      return formatdatetime
    }
  }
};
</script>
<style lang="css" scoped>
@import "../../css/activity.css";
</style>
